
package red.mlz.gameservice.mapper.gametagrelation;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import red.mlz.common.entity.gametagrelation.GameTagRelation;

import java.util.List;

@Mapper
public interface GameTagRelationMapper {

    // 根据ID查询操作
    @Select("select * from game_tag_relation WHERE id =  #{gameTagRelationId} AND is_deleted=0")
    GameTagRelation getById(Long gameTagRelationId);

    // 根据ID提取操作
    @Select("select * from game_tag_relation WHERE id =  #{gameTagRelationId}")
    GameTagRelation extractById(Long gameTagRelationId);

    // 插入操作
    Integer insert(GameTagRelation gameTagRelation);

    // 更新操作
    Integer update(GameTagRelation gameTagRelation);

    // 删除操作
    @Update("update game_tag_relation SET update_time = #{updateTime}, is_deleted = 1 WHERE id = #{id}")
    Integer delete(@Param("updateTime") Integer updateTime, @Param("id") Long id);

    @Update("update game_tag_relation SET update_time = #{updateTime} , is_deleted = 1 WHERE game_id = #{gameId}")
    void deleteByGameId(@Param("updateTime") Integer updateTime, @Param("gameId")  Long gameId);

    @Select("select * from game_tag_relation WHERE game_id = #{gameId} AND tag_id = #{tagId} AND is_deleted = 0")
    GameTagRelation getByGameIdAndTagId(@Param("gameId") Long gameId, @Param("tagId") Long tagId);

    @Select("select * from game_tag_relation WHERE game_id = #{gameId} AND is_deleted = 0")
    List<GameTagRelation> getByGameId(@Param("gameId") Long gameId);

    @Select("select * from game_tag_relation WHERE game_id = #{gameId} AND tag_id = #{tagId} AND is_deleted = 1")
    GameTagRelation getDeletedByGameIdAndTagId(@Param("gameId") Long gameId, @Param("tagId") Long tagId);

    @Select("select * from game_tag_relation WHERE game_id = #{gameId} AND is_deleted = 0")
    List<GameTagRelation> findByGameId(@Param("gameId") Long gameId);
}
